import 'dart:convert' show json;
import 'package:x3_base_core/base_models/base_model_asT.dart';

class BaseTokenModel {
  BaseTokenModel({this.userId, this.userName, this.authorizationCode, this.cloudErpId, this.branchId, this.depotManager, this.userIconUrl, this.loginAccount, this.loginPassword, this.userType, this.effectiveTime = "", this.companyId, this.companyName});

  factory BaseTokenModel.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : BaseTokenModel(
          userId: asT<String>(jsonRes['cloudErpId']),
          userName: asT<String>(jsonRes['userName']),
          authorizationCode: asT<String>(jsonRes['authorizationCode']),
          cloudErpId: asT<String>(jsonRes['cloudErpId']),
          branchId: asT<String>(jsonRes['branchId']),
          depotManager: asT<bool>(jsonRes['depotManager']),
          userIconUrl: asT<String>(jsonRes['userIconUrl']),
          loginAccount: asT<String>(jsonRes['loginAccount']),
          loginPassword: asT<String>(jsonRes['loginPassword']),
          userType: asT<int>(jsonRes['userType']),
          companyId: asT<String>(jsonRes['companyId']),
          companyName: asT<String>(jsonRes['companyName']),
          effectiveTime: asT<String>(jsonRes['effectiveTime']) ?? DateTime.now().add(Duration(days: 15)).toLocal().toString(),
        );

  String userId;
  String userName;
  String cloudErpId;
  String branchId;
  bool depotManager;
  String userIconUrl;
  String loginAccount;
  String loginPassword;
  int userType;
  String companyId;
  String companyName;
  String effectiveTime;
  String authorizationCode;

  Map<String, dynamic> toJson() => <String, dynamic>{'userId': userId, 'userName': userName, 'authorizationCode': authorizationCode, 'cloudErpId': cloudErpId, 'branchId': branchId, 'depotManager': depotManager, 'userIconUrl': userIconUrl, 'loginAccount': this.loginAccount, 'loginPassword': this.loginPassword, 'userType': this.userType, 'companyName': this.companyName, "effectiveTime": effectiveTime, "companyId": companyId};

  @override
  String toString() {
    return json.encode(this);
  }
}
